#pragma once
//-------------------------------------------------------------------------------------------------
//ArchiveProcGUIDoc.h : interface of the CArchiveProcGUIDoc class           
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk July 2011
//
//----Comments-------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------

//#include <vector>
#include "Observer.h"
#include "ResourceList.h"
#include "ImageDataset.h"
#include "ImageProps.h"
#include "DrawingTools.h"


class CArchiveProcGUIDoc : public CDocument
{
public:
	//static const LPARAM Save = 1L;
	//static const LPARAM Load = 0L;
					//values for UpdateAllViews( lHint ) - keep in sync with CArchiveProcGUIDoc::GetUpdateHintStr(LPARAM lHint)
	static const int UpdateAllViewsMFCFramework = 0;					//MFC framework has invoked UpDateAllViews()
	static const int UpdateAllViewsSetNewImage = 1;						//user has selected new image in TreeView (ArchiveProcGUIView). It becomes the current image: m_pSelImageProps
	static const int UpdateAllViewsSetBrightnessContrast = 2;			//user has changed the brightness or contrast settings for the current image
	static const int UpdateAllViewsSetNewImageType = 3;					//user has changed the image type setting (m_pSelImageProps->_pSelImageType) for the current image - new selection from PropertyWnd's ImageType combo
	static const int UpdateAllViewsSetNewImageObject = 4;				//user has changed the currently selected image object (m_pSelImageProps->_pSelImageObject) for the current image - change to PropertyWnd's ImageObject combo
	static const int UpdateAllViewsSetNewTool = 5;						//user has changed the tools | drawing menu selection 
	static const int UpdateAllViewsCreateImageObject = 6;				//user has pressed left mouse button on the Image Form's PictureCtrl to create an Image Object (type determined by tools | drawing menu selection)
	static const int UpdateAllViewsCompleteImageObject = 7;				//user has released left mouse button on the Image Form's PictureCtrl to complete creation of an Image Object (type determined by tools | drawing menu selection)
	static const int UpdateAllViewsUpdateImageObject = 8;				//user has dragged the mouse without releasing the left button to update the Image Object (tracing along the boundary of the image object)
	static const int UpdateAllViewsDeleteImageObject = 9;				//user has selected Edit | Erase to delete the currently selected Image Object 
	static const int UpdateAllViewsOpenDoc = 10;						//clear tree, clear image from PictureCtrl, clear image props, load images from doc, select first image and update UI
	static const int UpdateAllViewsSave = 11;							//tell all views to save changes in their UI controls to the doc (UpdateData())
	static const int UpdateAllViewsChangeImageObjectDisplay = 12;		//user has selected View | Hide Image Objects or View | Show Image Objects
	static const int UpdateAllViewsCloseDoc = 13;						//clear tree, clear image from PictureCtrl, clear image props

protected: // create from serialization only
	CArchiveProcGUIDoc();
	DECLARE_DYNCREATE(CArchiveProcGUIDoc)

// Attributes
public:

// Operations
public:

// Overrides
public:
	virtual BOOL OnNewDocument();
//	virtual void Serialize(CArchive& ar);
#ifdef SHARED_HANDLERS
	virtual void InitializeSearchContent();
	virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
#endif // SHARED_HANDLERS

// Implementation
public:
	virtual ~CArchiveProcGUIDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	ResourceList   m_ResourceIDList;	
	ImageDataset  *m_pIdfDoc;
	ImageProps    *m_pSelImageProps;
	DrawingTools   m_DrawingTools;
	ImageObjectTypeTool *m_pSelTool;
	bool		   m_HideImageObjects;



// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()

#ifdef SHARED_HANDLERS
	// Helper function that sets search content for a Search Handler
	void SetSearchContent(const CString& value);
#endif // SHARED_HANDLERS
public:
	static  CArchiveProcGUIDoc *GetActiveDoc();

	ImageDataset *GetImageDatasetFile() { return m_pIdfDoc; }
	ImageProps	 *GetSelImageProperties() { return m_pSelImageProps; }		//properties of the image selected in TreeView and displayed in PictureCtrl
	ImageObjectTypeTool *GetSelImageObjectTypeTool() { return m_pSelTool; }
	DrawingTools *GetDrawingTools() { return &m_DrawingTools; }

	ImageObjectTypeTool *GetToolForImageObject(ImageObject *pImageObject) { return GetDrawingTools()->GetToolForImageObject(pImageObject); }

	bool		  IsIDFDocumentLoaded() { return ((m_pIdfDoc != '\0') ? m_pIdfDoc->IsValidIDFFile() : false); } 
	bool		  IsMatchSelImageDicomRef(CString &DicomRef) { return (m_pSelImageProps != '\0') ? (DicomRef == m_pSelImageProps->GetDicomRef()): '\0'; }
	const char   *GetSelImageDicomRef() { return ((m_pSelImageProps != '\0') ? m_pSelImageProps->GetDicomRef() : '\0'); }
	const char   *GetSelImagePathFileName() { return ((m_pIdfDoc != '\0') ? m_pIdfDoc->GetSelImagePathFileName() : '\0'); }
	bool		  IsValidSelectedImage() { return (m_pSelImageProps != '\0') ? m_pSelImageProps->IsValidSelectedImage() : false; }
	bool		  IsShowImageObjects() { return (m_HideImageObjects == true) ? false : true; }
	bool		  SetSelImageProperties(ImageProps *pProp);
	bool		  SetSelImageObjectTypeTool(ImageObjectTypeTool *pSelTool); 

	bool		  SetupDynamicMenus(CMFCPopupMenu* pMenuPopup, int iIndex);
	bool		  SelectDymanicMenu(int ResourceId);
	bool		  DrawImageDynamicMenu(CDC* pDC, const CMFCToolBarMenuButton* pMenuButton, const CRect& rectImage);
	bool		  IsDynamicMenuId(int Id) { return m_ResourceIDList.IsFound(Id); }

	static const char   *GetUpdateHintStr(LPARAM lHint);

	void		 DoUpdateAllViews(CWnd *pSender, int UpdateAllViewslHint, CObject *pObj);
	bool		 DoSelectImage( CTreeView *pView, const char *DicomRef);			//called by CTreeView (ArchiveProcGUIView) when an image is selected - sets the UI from image's properties
	bool		 DoChangeBrightness(int val);
	bool		 DoChangeContrast(int val);

	virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
	virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);

	afx_msg void OnToolsOptions();
	afx_msg void OnViewSetDefaultBrightness();
	afx_msg void OnUpdateSetDefaultBrightness(CCmdUI *pCmdUI);
	afx_msg void OnViewSetDefaultContrast();
	afx_msg void OnUpdateSetDefaultContrast(CCmdUI *pCmdUI);
	afx_msg void OnViewHideImageObjects();
	afx_msg void OnUpdateViewHideImageObjects(CCmdUI *pCmdUI);
	virtual void OnCloseDocument();
};


//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------
